// ==UserScript==
// @name         自动网络学习
// @namespace    111
// @version      0.2
// @description  try to take over the world!
// @author       You
// @match        https://www.hljgbjy.org.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=hljgbjy.org.cn
// @grant        none
// @require
// @run-at       document-end
// @downloadURL https://raw.gitcode.com/nihao900/ljxx/raw/main/zdxx.user.js
// @updateURL https://raw.gitcode.com/nihao900/ljxx/raw/main/update.js
// ==/UserScript==


var dz
var jdsz
var current_video

(function() {

    'use strict';
    /* window.onhashchange = function() {
    console.log('The hash has changed!');
    var currentHash = window.location.hash;
    console.log('New hash:', currentHash);
};*/

    var dz=window.location.href
    //alert(dz)
    if(dz=="https://www.hljgbjy.org.cn/#/personalCenter")
    {
        setTimeout(function(){
            var str=document.querySelector('a.title.ng-binding').href;
//alert(str);
            if(!str){alert("无课程");throw new Error('程序遇到了一个无法恢复的错误，必须停止运行');}
            var kcid=str.substring(str.indexOf('=')+1,);
            // 打开一个新窗口
            /*var newWindow = window.open('https://www.hljgbjy.org.cn/#/play/play?Id='+kcid,'_blank');

// 如果浏览器支持，监听新窗口的 load 事件
if (newWindow.addEventListener) {
  newWindow.addEventListener('load', function() {
   // console.log('新窗口加载完成');
      window.close();
  });
}*/
            window.open('https://www.hljgbjy.org.cn/#/play/play?Id='+kcid,'_blank');

        },5000)
        //setTimeout(function(){window.close()},5000)
    }
    else if(dz.includes("https://www.hljgbjy.org.cn/#/play/play?Id"))
    {
        setTimeout(function(){document.getElementsByClassName('btn')[0].click()},5000)
        pdsp()
    }
})();
function pdsp()//判断视频是否加载
{var intervalId =setInterval(function() {
    // alert(document.getElementsByTagName('video')[0]);
    current_video = document.getElementsByTagName('video')[0];
    if(document.getElementsByTagName('video')[0]!=undefined)
    {
        // alert("123");
        clearInterval(intervalId);
        jdpd();
    }
}, 1000)
}

function jd()//获取进度值
{var jdtext=document.getElementsByClassName('progress-bar progress-bar-striped ng-binding')[0].innerText
jdsz=parseInt(jdtext.substring(0, jdtext.lastIndexOf('.')))
}
function jdpd()//进度判断
{
    var intervalId = setInterval(function(){
        jd();
        if(jdsz<100){current_video.play()}
        else{
            clearInterval(intervalId);
            window.open("https://www.hljgbjy.org.cn/#/personalCenter",'_blank');
            window.close();
        }
    },1000)
    }





